package com.androider.timememory.utils;

import com.androider.timememory.R;
import com.androider.timememory.db.Record;

import android.content.Context;
import android.content.res.Resources;
import android.widget.CheckBox;

public class RecordUtil {
	
	public static final String LIST_TYPE_TEXT = "文字笔记";
	public static final String LIST_TYPE_PHOTO = "照片";
	public static final String LIST_TYPE_VIDEO = "视频";
	public static final String LIST_TYPE_AUDIO = "录音";
	
	public static String getCategory(CheckBox family, CheckBox lover, CheckBox friend) {
		boolean isFamily = family.isChecked();
		boolean isLover = lover.isChecked();
		boolean isFriend = friend.isChecked();
		
		if(!isFamily && !isLover && !isFriend) {
			return null;
		}
		
		StringBuilder category = new StringBuilder("");
		if(isFamily) {
			category.append(Constants.DATA_TYPE_FAMILY);
		}
		if(isLover) {
			category.append(Constants.DATA_TYPE_LOVER);
		}
		if(isFriend) {
			category.append(Constants.DATA_TYPE_FRIEND);
		}
		return category.toString();
	}
	
	/**
	 * Transform integer to string source id
	 * @param context
	 * @param type
	 * @return string source id
	 */
	public static String getType(Context context, int type) {
	    String str = "";
	    switch(type) {
	        case Record.TYPE_TEXT:
	            str = context.getResources().getString(R.string.list_type_text);
	            break;
	        case Record.TYPE_PHOTO:
	            str = context.getResources().getString(R.string.list_type_photo);
	            break;
            case Record.TYPE_VIDEO:
                str = context.getResources().getString(R.string.list_type_video);
                break;
            case Record.TYPE_AUDIO:
                str = context.getResources().getString(R.string.list_type_audio);
                break;
            default:
                break;
	    }
	    return str;
	}
	
	public static String getCategoryName(Context context, String category) {
		if(null == category || category.equals("")) {
			return null;
		}
		
		Resources res = context.getResources();
		String text = "";
		String family = res.getString(R.string.category_family); 
		String lover = res.getString(R.string.category_lover); 
		String friend = res.getString(R.string.category_friend); 
		
		if(category.equals(Constants.DATA_TYPE_FAMILY)) {
			text = family;
		} else if(category.equals(Constants.DATA_TYPE_LOVER)) {
			text = lover;
		} else if(category.equals(Constants.DATA_TYPE_FRIEND)) {
			text = friend;
		} else if(category.equals("ab")) {
			text = family + lover;
		} else if(category.equals("bc")) {
			text = lover + friend;
		} else if(category.equals("ac")) {
			text = family + friend;
		} else if(category.equals("abc")) {
			text = family + lover + friend;
		} 
		return text;
	}
	
	/**
	 * Transform string to drawable source id
	 * @param category the string store in the database
	 * @return drawable source id
	 */
	public static int getCategory(String category) {
	    int resId = -1;
	    if(null == category || category.equals("")) {
	        return resId;
	    }
	    
        if(category.equals(Constants.DATA_TYPE_FAMILY)) {
            resId = R.drawable.one_flag_a;
        } else if(category.equals(Constants.DATA_TYPE_LOVER)) {
            resId = R.drawable.one_flag_b;
        } else if(category.equals(Constants.DATA_TYPE_FRIEND)) {
            resId = R.drawable.one_flag_c;
        } else if(category.equals("ab")) {
            resId = R.drawable.double_flag_ab;
        } else if(category.equals("bc")) {
            resId = R.drawable.double_flag_bc;
        } else if(category.equals("ac")) {
            resId = R.drawable.double_flag_ac;
        } else if(category.equals("abc")) {
            resId = R.drawable.triple_flag;
        } 
        return resId;
    }
}
